<?php

require_once("../config/start.php");
require_module("linkit");



$parameters =& $_GET;
if(!$parameters) $parameters =& $_POST;

$url = @$parameters["url"];
$collection = @$parameters["collection"];
$return = @$parameters["return"];
$action = @$parameters["action"];
$callback = @$parameters["callback"];

$request_uri = $_SERVER["REQUEST_URI"];
if(preg_match("/[&\?]url=(.*)$/", $request_uri, $arr)) $url = $arr[1];

if(!$action) $action = "replace_with_link";

$return = "";
if(!$url)
{
    $return = "";
}elseif(!$collection || !method_exists('NameLookup', $collection))
{
    $collection = "gni";
    $html = LinkIT::markup_html_from_url($url, false);
    $html = LinkIT::wrap_tags($html, "<b>", "</b>");
    $html .= '<linkit_collection class="linkit_collection" id="linkit_collection_1" action="'.$action.'" name="'.$collection.'" />';
    
    $return = $html;
}elseif($return)
{
    $html = LinkIT::markup_html_from_url($url, false);
    $html = LinkIT::replace_tags_with_collection($html, "NameLookup::$collection");
    $html .= '<linkit_collection class="linkit_collection" id="linkit_collection_1" action="'.$action.'" name="'.$collection.'" />';
    
    $return = $html;
}else
{
    $html = LinkIT::markup_html_from_url($url);
    $html .= '<linkit_collection class="linkit_collection" id="linkit_collection_1" action="'.$action.'" name="'.$collection.'" />';
    
    $return = $html;
}

if($callback)
{
    $return = array("html" => $return);
    echo "$callback(".json_encode($return).")";
}else
{
    echo $return;
}




//LinkIT::markup_html_from_url("http://localhost/linkit/doc/blank.html");

//LinkIT::markup_html_from_url("http://www.apsnet.org/online/common/names/cucurbit.asp");
//LinkIT::markup_html_from_url("http://www.tolweb.org/Homo_sapiens/16421");
//LinkIT::markup_html_from_url("http://www.csdl.tamu.edu/FLORA/gallery.htm");

//LinkIT::markup_html_from_url("http://www.weather.com/outlook/travel/businesstraveler/local/02360");



?>